import csv
import numpy as np
import pandas as pd
list_totol=[]
#处理sys_dict_data
df=pd.read_csv('sys_dict_data.csv',encoding='utf-8')
result=df.loc[df['dict_label']=='水泥']
if not result.empty:
    for index, row in result.iterrows():
        print(f"dict_label: {row['dict_label']}, dict_value: {row['dict_value']},dict_type: {row['dict_type']}")
else:
    print("没有找到 '水泥' 在 dict_label 列中。")
result1=df.loc[df['dict_label']=='矿粉']
if not result1.empty:
    for index, row in result1.iterrows():
        print(f"dict_label: {row['dict_label']}, dict_value: {row['dict_value']},dict_type: {row['dict_type']}")
else:
    print("没有找到 '矿粉' 在 dict_label 列中。")
#处理ERP_FHJL
third = open(file='ERP_FHJL.csv',mode='r',encoding='utf-8')
result_1 = third.read()
list1=result_1.split('\n')
list_name=list1[0]
list_name=list_name.split(',')
length3=len(list_name)
for i in range(length3):
    if list_name[i]=='jz':
        break
    else:
        continue
x=i
'''
print(x)
'''
df3=pd.read_csv('ERP_FHJL.csv',encoding='utf-8')
x_column=df3.iloc[:,x]
'''
print(x_column)
'''
for i in range(length3):
    if list_name[i]=='hplx':
        break
    else:
        continue
y=i
'''
print(y)
'''
df3=pd.read_csv('ERP_FHJL.csv',encoding='utf-8')
y_column=df3.iloc[:,y]
'''
print(y_column)
'''
for i in range(length3):
    if list_name[i]=='create_time':
        break
    else:
        continue
z=i
z_column=df3.iloc[:,z]
for i in range(length3):
    if list_name[i]=='hk':
        break
    else:
        continue
x=i
q_column=df3.iloc[:,z]
df_combined = pd.DataFrame({'jz_values': x_column, 'hplx_values': y_column,'hk':q_column,'material':np.where(y_column==0,'水泥','矿粉'),'create_time':z_column})
df_combined['create_time']=pd.to_datetime(df_combined['create_time'])
df_2023=df_combined[df_combined['create_time'].dt.year==2023]
# 打印结果
'''
print(df_combined)
'''
# 选择hplx_values为0的行
rows_with_zero = df_2023[df_2023['hplx_values'] == 0]
# 输出这些行中的jz_values和hplx_values
print(rows_with_zero[['jz_values','hk', 'hplx_values','material','create_time']])
rows_with_one = df_2023[df_2023['hplx_values'] == 1]
# 输出这些行中的jz_values和hplx_values
print(rows_with_one[['jz_values', 'hk','hplx_values','material','create_time']])
# 筛选是水泥的行并计算jz_values的总和
jz_values_sum_cement = df_2023[df_2023['material'] == '水泥']['jz_values'].sum()
print(f"水泥的jz_values总和: {jz_values_sum_cement}")

# 筛选矿粉的行并计算jz_values的总和
jz_values_sum_mineral_powder = df_2023[df_2023['material'] == '矿粉']['jz_values'].sum()
print(f"矿粉的jz_values总和: {jz_values_sum_mineral_powder}")